package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.XYBtn;
import com.tool.image.ImageMixDeal;
import com.tool.tcp.Sprite;
import com.tool.tcp.SpriteFactory;
import com.tool.tcpimg.UIUtils;
import org.come.mouslisten.WLLMouslisten;
import org.come.until.CutButtonImage;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class XYJpanel extends JPanel {
    public static String num="11";
    public static XYBtn []xiulian=new XYBtn[16];
    public XYBtn QICHENG;
    public XYBtn CHONGZHI;
    public static XYBtn[] xinlu=new XYBtn[3];
    public static  String jidian=null;

    static Sprite leftLine = SpriteFactory.VloadSprite("skin/8100226/mouse/xy_leftLine", null);//特效路径

    public static Map<Integer,Integer> pointRule = new HashMap<>();

    public XYJpanel() {

        pointRule.put(0,0);
        pointRule.put(1,0);
        pointRule.put(2,2);
        pointRule.put(10,4);
        pointRule.put(9,4);
        pointRule.put(8,2);
        pointRule.put(3,1);
        pointRule.put(4,3);
        pointRule.put(5,6);
        pointRule.put(6,7);
        pointRule.put(7,10);
        pointRule.put(11,1);
        pointRule.put(12,3);
        pointRule.put(13,6);
        pointRule.put(14,7);
        pointRule.put(15,10);

        setPreferredSize(new Dimension(901, 548));
        setOpaque(false);
        setLayout(null);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("skin/8100226/button/1.png", 1, 124);// 800 10
        offBtn.setBounds(800, 10, 25, 25);
       this.add(offBtn);
        //腾云
       xiulian[0]=new XYBtn("inkImg/old/background/S414.png",1,0,this);
        xiulian[0].setBounds(465,355,27,27);
        xiulian[0].addMouseListener(new WLLMouslisten(80));
       this.add(xiulian[0]);

           //破云
        xiulian[1]=new XYBtn("inkImg/old/background/S414.png",1,1,this);
        xiulian[1].setBounds(397,323,27,27);
        xiulian[1].addMouseListener(new WLLMouslisten(81));
        //xiulian[0].setVisible(false);
        this.add(xiulian[1]);
        //踏云
        xiulian[2]=new XYBtn("inkImg/old/background/S414.png",1,2,this);
        xiulian[2].setBounds(389,226,27,27);
        xiulian[2].addMouseListener(new WLLMouslisten(82));
        //xiulian[0].setVisible(false);
        this.add(xiulian[2]);
        //圣佑
        xiulian[3]=new XYBtn("inkImg/old/background/S414.png",1,3,this);
        xiulian[3].setBounds(327,423,27,27);
        xiulian[3].addMouseListener(new WLLMouslisten(83));
        //xiulian[0].setVisible(false);
        this.add(xiulian[3]);
        //情心
        xiulian[4]=new XYBtn("inkImg/old/background/S414.png",1,4,this);
        xiulian[4].setBounds(239,331,27,27);
        xiulian[4].addMouseListener(new WLLMouslisten(84));
        //xiulian[0].setVisible(false);
        this.add(xiulian[4]);
        //神通
        xiulian[5]=new XYBtn("inkImg/old/background/S414.png",1,5,this);
        xiulian[5].setBounds(211,199,27,27);
        xiulian[5].addMouseListener(new WLLMouslisten(85));
        //xiulian[0].setVisible(false);
        this.add(xiulian[5]);
        //义心
        xiulian[6]=new XYBtn("inkImg/old/background/S414.png",1,6,this);
        xiulian[6].setBounds(276,171,27,27);
        xiulian[6].addMouseListener(new WLLMouslisten(86));
        //xiulian[0].setVisible(false);
        this.add(xiulian[6]);
        //悟影
        xiulian[7]=new XYBtn("inkImg/old/background/S414.png",1,7,this);
        xiulian[7].setBounds(234,114,27,27);
        xiulian[7].addMouseListener(new WLLMouslisten(87));
        //xiulian[0].setVisible(false);
        this.add(xiulian[7]);
        //追云
        xiulian[8]=new XYBtn("inkImg/old/background/S414.png",1,8,this);
        xiulian[8].setBounds(553,318,27,27);
        xiulian[8].addMouseListener(new WLLMouslisten(88));
        //xiulian[0].setVisible(false);
        this.add(xiulian[8]);
        //潜云
        xiulian[9]=new XYBtn("inkImg/old/background/S414.png",1,9,this);
        xiulian[9].setBounds(549,225,27,27);
        xiulian[9].addMouseListener(new WLLMouslisten(89));
        //xiulian[0].setVisible(false);
        this.add(xiulian[9]);
        //纵云
        xiulian[10]=new XYBtn("inkImg/old/background/S414.png",1,10,this);
        xiulian[10].setBounds(469,183,27,27);
        xiulian[10].addMouseListener(new WLLMouslisten(90));
        //xiulian[0].setVisible(false);
        this.add(xiulian[10]);
        //魔威
        xiulian[11]=new XYBtn("inkImg/old/background/S414.png",1,11,this);
        xiulian[11].setBounds(614,411,27,27);
        xiulian[11].addMouseListener(new WLLMouslisten(91));
        //xiulian[0].setVisible(false);
        this.add(xiulian[11]);
        //逍心
        xiulian[12]=new XYBtn("inkImg/old/background/S414.png",1,12,this);
        xiulian[12].setBounds(698,328,27,27);
        xiulian[12].addMouseListener(new WLLMouslisten(92));
        //xiulian[0].setVisible(false);
        this.add(xiulian[12]);
        //灵通
        xiulian[13]=new XYBtn("inkImg/old/background/S414.png",1,13,this);
        xiulian[13].setBounds(727,195,27,27);
        xiulian[13].addMouseListener(new WLLMouslisten(93));
        //xiulian[0].setVisible(false);
        this.add(xiulian[13]);
        //遥心
        xiulian[14]=new XYBtn("inkImg/old/background/S414.png",1,14,this);
        xiulian[14].setBounds(665,166,27,27);
        xiulian[14].addMouseListener(new WLLMouslisten(94));
        //xiulian[0].setVisible(false);
        this.add(xiulian[14]);
        //六识
        xiulian[15]=new XYBtn("inkImg/old/background/S414.png",1,15,this);
        xiulian[15].setBounds(701,101,27,27);
        xiulian[15].addMouseListener(new WLLMouslisten(95));
        //xiulian[0].setVisible(false);
        this.add(xiulian[15]);

        for (int i=1;i<=xiulian.length-1;i++){
            if (xiulian[i]!=null){
                xiulian[i].setBounds(xiulian[i].getX()-8,xiulian[i].getY()-8,27,27);
            }
        }
        QICHENG=new XYBtn("skin/8100226/mouse/xyBigBtn.png",1,44,this,"确认加点");
        QICHENG.setBounds(420,460,120,50);
        this.add(QICHENG);

        CHONGZHI=new XYBtn("skin/8100226/mouse/xy_xd.png",1,46,this,"");
        CHONGZHI.setBounds(200,430,80,50);
        this.add(CHONGZHI);
        xinlu[0]=new XYBtn("skin/8100226/button/心路2.png",1,16,this,1);
        xinlu[0].setBounds(803,104,37,82);
        this.add(xinlu[0]);
        xinlu[1]=new XYBtn("skin/8100226/button/心意1.png",1,17,this,1);
        xinlu[1].setBounds(803,184,37,82);
        this.add(xinlu[1]);

        xinlu[2]=new XYBtn("skin/8100226/button/心经2.png",1,18,this,1);
        xinlu[2].setBounds(803,264,37,82);
        this.add(xinlu[2]);

        for (int i = 0; i < xiulian.length; i++) {
            xydkbArr[i] = SpriteFactory.VloadSprite("skin/8100226/mouse/xydkb", null);
        }
    }
    private ImageIcon icon;

    static Sprite xybj = SpriteFactory.VloadSprite("skin/8100226/mouse/xybj", null);//特效路径
    static Sprite right = SpriteFactory.VloadSprite("skin/8100226/mouse/xy_right", null);//特效路径
    static Sprite xyzj = SpriteFactory.VloadSprite("skin/8100226/mouse/xyzj", null);//特效路径
    static Sprite xyzjrw = SpriteFactory.VloadSprite("skin/8100226/mouse/xyzjrw", null);//特效路径
    static Sprite xycszl = SpriteFactory.VloadSprite("skin/8100226/mouse/xycszl", null);//特效路径
    Sprite xydkb = SpriteFactory.VloadSprite("skin/8100226/mouse/xydkb", null);//特效路径

    Sprite[] xydkbArr = new Sprite[16];

    private ImageIcon xyxt =  new ImageIcon("skin/8100226/button/心条.png");

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        if(xybj != null){
            xybj.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xybj.draw(g, 0, 0);
        }

        if(xyzjrw != null){
            xyzjrw.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xyzjrw.draw(g, 83, 0);
        }

        if(xycszl != null){
            xycszl.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xycszl.draw(g, 10, 50);
        }



        if (icon == null) {
            icon = new ImageIcon("skin/8100226/mouse/S411(1).png");
        }

        g.drawImage(xyxt.getImage(), 806, 60, 26, 411, this);

        g.drawImage(icon.getImage(), 0, 0, 901, 548, this);
        g.setColor(new Color(192, 177, 100));
        g.setFont(UIUtils.TEXT_FONT79);
        g.drawString(getNum(),240,430);


        if(leftLine != null){
            leftLine.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            leftLine.draw(g, 148, 68);
        }

        if(right != null){
            right.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            right.draw(g, 570, 68);
        }


        for (int i = 0; i < xiulian.length; i++) {
            Rectangle bounds = xiulian[i].getBounds();
            xydkbArr[i].updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xydkbArr[i].draw(g, (int)bounds.getX(), (int)bounds.getY());
        }

        if(xyzj != null){
            xyzj.updateToTime(ImageMixDeal.userimg.getTime(), 0);
            xyzj.draw(g, 338, 145);
        }

        g.setColor(new Color(192, 177, 100));
        g.setFont(UIUtils.TEXT_FONTYH15);
        g.drawString("心意点", 185, 430);


    }

    public String getNum() {
    if (num==null) {
        num= String.valueOf(0);
    }
        return num;
    }
    public static void CS(int k,String mes){
//        jidian = "";
        if (mes==null){
            for (int i=0;i<=15;i++){
                try {
                    xiulian[i].setIcons(CutButtonImage.cuts("inkImg/old/background/S414.png"));
                    xiulian[i].setText("");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            num= String.valueOf(k);
            jidian=null;
            return;
        }
        num= String.valueOf(k);
        String[] mes1=mes.split("#");
        for (int i=0;i<=15;i++){
            try {
                xiulian[i].setIcons(CutButtonImage.cuts("inkImg/old/background/S414.png"));
                xiulian[i].setText("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        jidian = "";
        for (int i=1;i<=mes1.length-2;i++){
            if ("".equals(mes1[i])) {
                continue;
            }
            try {
                xiulian[Integer.parseInt("null".equals(mes1[i]) ? "0" : mes1[i])].setIcons(CutButtonImage.cuts("inkImg/old/background/S412.png"));
                // XYXYDJpanel.panduan[i]=1;
                xiulian[Integer.parseInt("null".equals(mes1[i]) ? "0" : mes1[i])].setText("true");
                jidian = jidian + "#"+mes1[i];
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
    public void setNum(String num) {
        XYJpanel.num = num;
    }

    public static XYBtn[] getXiulian() {
        return xiulian;
    }

    public void setXiulian(XYBtn[] xiulian) {
        XYJpanel.xiulian = xiulian;
    }

    public static String getJidian() {
        return jidian;
    }

    public static void setJidian(String jidian) {
        XYJpanel.jidian = jidian;
    }
}
